<?php

namespace App\Repositories;

use App\Models\Profession;

class ProfessionRepository
{

    public function getList($skey = null )
    {
        $cache_key = "cache_profession_list_" . md5($skey);

        $res = \Cache::get($cache_key);
        if(empty($res)){
            $res =  Profession::query()
                ->when(!empty($skey), function ($query) use ($skey){
                    return $query->where('title', "like", "%$skey%");
                })
                ->where("status", "=", 1)
                ->orderBy("id", "asc" )
                ->get(['id','title'])
                ->toArray();

            \Cache::set($cache_key, $res);
        }

        return $res;
    }

}